{include file='common/head'}
<div style="overflow-x: hidden;width: 96%;margin: auto;padding-top: 1rem;">


    <div class="layui-form" action="" method="post">
        <div class="layui-form-item">
            <label class="layui-form-label">角色类型</label>
            <div class="layui-col-xs3">
                <select name="role_id" lay-filter="roleselect">
                    <option value="">筛选角色类型</option>
                    <option value="1">保险公司人员</option>
                    <option value="2">代录人</option>
                    <option value="3">被保险人</option>
                    <option value="4">业务员</option>
                    <option value="5">其他人员</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item recoderType" style="display: none">
            <label class="layui-form-label">代录人类型</label>
            <div class="layui-col-xs3">
                <select name="recoder_type">
                    {foreach $RecorderType as $v}
                    <option value="{$v.id}">{$v.name}</option>
                    {/foreach}
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">员工名称</label>
            <div class="layui-col-xs3">
                <input type="text" name="username"  lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">手机号</label>
            <div class="layui-col-xs3">
                <input type="text" name="mobile"  lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
            </div>
        </div>
        <!--<div class="layui-form-item">-->
            <!--<label class="layui-form-label">密码</label>-->
            <!--<div class="layui-col-xs3">-->
                <!--<input type="password" name="password"  lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">-->
            <!--</div>-->
        <!--</div>-->
        <div class="layui-form-item">
            <label class="layui-form-label">身份证号</label>
            <div class="layui-col-xs3">
                <input type="text" name="id_number"  lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">单位</label>
            <div class="layui-col-xs3">
                <input type="text" name="company"  lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
            </div>
        </div>
        <div class="saleMan" style="display: none;">
        <div class="layui-form-item">
            <label class="layui-form-label">业务员单位名称：</label>
            <div class="layui-col-xs3">
                <input type="text" name="sale_man_company"  lay-verify="title" autocomplete="off" placeholder="请输入业务员单位名称" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">业务员单位联系人</label>
            <div class="layui-col-xs3">
                <input type="text" name="sale_man_linkman"  lay-verify="title" autocomplete="off" placeholder="请输入业务员单位联系人" class="layui-input">
            </div>
        </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="demo1">保存</button>
            </div>
        </div>
    </div>
</div>
{include file='common/footer'}
<script>
    layui.use('layedit', function(){
        var layedit = layui.layedit;
        layedit.set({
            uploadImage: {
                url: '{:url("Upload/file_content")}' //接口url
                ,type: 'post' //默认post
            }
        });
        //注意：layedit.set 一定要放在 build 前面，否则配置全局接口将无效。
    });
</script>
<script>
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;

        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });

        //创建一个编辑器
        var editIndex = layedit.build('demo');

        //自定义验证规则
        form.verify({
            pass: [/(.+){6,12}$/, '密码必须6到12位']
            ,content: function(value){
                layedit.sync(editIndex);
            }
        });

        //监听指定开关
        form.on('switch(switchTest)', function(data){
            layer.msg('开关checked：'+ (this.checked ? 'true' : 'false'), {
                offset: '6px'
            });
            layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        });

        //监听角色类型选项
        form.on('select(roleselect)',function(data){
            $('.recoderType').hide();
            if(data.value == 2){ //代录人
                $('.recoderType').show();
            }
            $('.saleMan').hide();
            if(data.value == 4){ //业务员
                $('.saleMan').show();
            }
        })

        //监听提交
        form.on('submit(demo1)', function(data){
            $.ajax({
                url: '{:url("User/saveUserInfo")}',
                type: 'post',
                dataType: 'json',
                data: data.field,
                success: function (obj) {
                    if(obj.code==200){
                        parent.layer.msg(obj.msg, {icon: 6,time: 1000});
                        //当你在iframe页面关闭自身时
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index,data.field); //再执行关闭
                    }
                    if(obj.code==500){
                        layer.msg(obj.msg, {icon: 5,time: 1000});
                    }
                },
                error:function(data){
                    console.log(data);
                }
            });

        });
    });
</script>

</body>
</html>